package com.itbaizhan;

import com.itbaizhan.dao.impl.StudentDaoImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Container {
    static private Map<String, Object> map = new HashMap<>();

    static {
        InputStream is = Container.class.getClassLoader().getResourceAsStream("bean.properties");
        Properties properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        Enumeration<Object> keys = properties.keys();
        while (keys.hasMoreElements()){
            String key = keys.nextElement().toString();
            String value = properties.getProperty(key);
            Object o = null;
            try {
                o = Class.forName(value).newInstance();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            map.put(key,o);
        }
    }

    public static Object getBean(String key){
        return map.get(key);
    }
}
